$(document).ready(function() {

	var remoteTrans = new Helper.RemoteTrans({
		url:Helper.basePath+"/register.htm",
		onError:function(json){
			if(json.respCode ==="6005") {
				promptFailure($("#username")[0],json.message);
				_errorUserMap.put($("#username").val(),1);
			}else {
				Helper.message(json.message);
			}
		},
		onSuccess:function(json) {
			location.href=Helper.basePath+"/page/login/login.jsp";
		}
	});
	//点击注册
	$("#subfrm").click(function(){
		//var username=$("#username").val();
		var password=$("#password").val();
		var password_re=$("#password_re").val();
		var mobile=$("#mobile").val();
		var email = $("#email").val();
		var checkcode = $("#checkcode").val();
		var recommendCode = $("#recommendCode").val();
		var mobilecode = $("#mobilecode").val();
		var isagree = $("input[name='isagree']:checked").val();
		//var validataUname=Helper.validata.validataUname(username);
		var validataPass=Helper.validata.validataPass(password);
		var validataMobile=Helper.validata.validataMobile(mobile);
		var validataEmail= Helper.validata.validataEmail(email);
		/*if(validataUname){
			Helper.message(validataUname);
			return;
		} */
		if(validataPass){
			Helper.message(validataPass);
			return ;
		}
		if(password!=password_re){
			Helper.message("密码不一致");
			return;
		}
		if(validataMobile){
			Helper.message(validataMobile);
			return ;
		}
		/*if(validataEmail){
			Helper.message(validataEmail);
			return ;
		}*/
		if(checkcode.length<1){
			Helper.message("请输入图形验证码");
			return;
		}
		if(mobilecode.length<1){
			Helper.message("请输入手机验证码");
			return;
		}
		if (isagree == "" || isagree == null) {
			alert("请勾选同意《注册协议》");
			return;
		}
		remoteTrans.params = {mobile:mobile,password:password,recommendCode:recommendCode,mobilecode:mobilecode,checkcode:checkcode};
		remoteTrans.send();
	});
	//重新发送邮箱验证码
	$("#resendEmailActiveCode").click(function(){
		var remoteTrans_reactive = new Helper.RemoteTrans({
			url:Helper.basePath+"/resendEmailActiveCode.htm",
			onError:function(json){
				Helper.message(json.message);
			},
			onSuccess:function(json) {
				Helper.message("邮件已发送,请您注意查收");
			}
		});
		var mobile = $("#mobile").val();
		remoteTrans_reactive.params = {mobile:mobile};
		remoteTrans_reactive.send();
	});
	//发送短信验证码
	$("#sect_ch_mobilecode_g").click(function(){
		var mobile=$("#mobile").val();
		var validataMobile=Helper.validata.validataMobile(mobile);
		if(validataMobile){
			Helper.message(validataMobile);
			return ;
		}
		var sendRegValidSMS = new Helper.RemoteTrans({
			url:Helper.basePath+"/sendRegValidSMS.htm",
			onSuccess:function(json) {
				if(json.isSuccess==true){
					var timeInterval=json.returnValue;
					$("#sect_ch_mobilecode_g").hide();
					$("#sect_ch_mobilecode_h").show();
					var timmer=new Helper.Timmer({
						milli:1000,
						count:timeInterval,
						call:function(){
							timeInterval=timeInterval-1;
							if( timeInterval> 0) {
								$("#sect_ch_mobilecode_h").val(timeInterval+"秒后可重发");
							}else{
								$("#sect_ch_mobilecode_g").show();
								$("#sect_ch_mobilecode_h").hide();
							}
						}
					});
					Helper.message("短信发送成功，请注意查收！");
					timmer.start();
				}else{
					Helper.message(json.message);
				}
			},
			onError:function(json){
				Helper.message(json.message);
			}
		});
		sendRegValidSMS.params = {mobile:mobile};
		sendRegValidSMS.send();
	});
});

var RegisterCheckcode = function(id) {
	var newUrl = "";
	var oldUrl = $("#" + id).attr("src");
	if (oldUrl.indexOf("?") != -1) {
		newUrl = oldUrl.substring(0, oldUrl.indexOf("?")) + "?refresh="
				+ Math.random() * 100;
	} else {
		newUrl = oldUrl + "?refresh=" + Math.random() * 100;
	}
	//$("#" + id).attr("src", newUrl);
	$("img[id$=" + id + "]").attr("src", newUrl);
};